/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.Console;
import java.util.Scanner;

/**
 * <p>Project: javase202202 - Input3
 * <p>Powered by Lisi On 2022-05-31 14:11:16
 * <p>Created by IntelliJ IDEA
 *

 * @version 1.0
 * @since 17
 */
public class Input3 {
    public static void main(String[] args) {

        Console c = System.console();
        String pwd = "";
        if (c == null) {
            //使用模拟控制台 Scanner
            System.out.print("请输入密码");
            pwd = new Scanner(System.in).nextLine();
        } else {
            //使用真实控制台 windows linux
            String name = c.readLine("请输入姓名：");
            System.out.printf("欢迎：%s%n",name);

            //new String(char[]) 此实例化字符串，可以将char[] 对象直接转换为String对象
            pwd = new String(c.readPassword("请输入密码："));
        }
        System.out.println("你输入的密码是：" + pwd);
    }
}
